package xiaolong.lian.util;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpSession;

public class Session {
    public static void set(String key, String value, int validMin){
        HttpSession session = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getSession();
        session.setAttribute(key, value);
        session.setMaxInactiveInterval(60*validMin);
    }

    public static String get(String key){
        HttpSession session = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getSession();
        Object value = session.getAttribute(key);
        if(value == null)
            return null;
        return value.toString();
    }
}
